package com.smag.web.controller.farming.mall;

import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.system.service.FarmProductPictureService;
import com.smag.system.service.FarmCartService;
import com.smag.system.service.FarmOrderProductService;
import com.smag.system.service.FarmOrderService;
import com.smag.system.service.FarmProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 商品详情页
 */
@RestController
@RequestMapping("/farming/mall/product/detail")
public class DetailController extends BaseController {
    @Resource
    private FarmProductService farmProductService;

    @Resource
    private FarmCartService farmCartService;
    @Resource
    private FarmOrderService farmOrderService;
    @Resource
    private FarmProductPictureService farmProductPictureService;
    @Resource
    private FarmOrderProductService farmOrderProductService;


    /**
     * 根据id获取商品详情信息
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getDetail(@PathVariable("id") Long id){
        return AjaxResult.success(farmProductService.selectFarmProductById(id));
    }

//
//
//    /**
//     *
//     * @return
//     */
//    @PostMapping("")
//    public AjaxResult buyDirectly(@RequestBody FarmCart farmCart)
//    {
//        FarmOrderProduct farmOrderProduct = new FarmOrderProduct();
//        farmOrderProduct.setProductId(farmCart.getProductId());
//        farmOrderProduct.setpNumber(farmCart.getAmount());
//       // SecurityUtils.getUserId()
//        return toAjax(farmOrderProductService.insertOrderProduct(farmOrderProduct));
//    }


    @GetMapping("/getProductPicture")
    public AjaxResult getProductPicture(Long id){
        return farmProductPictureService.getProductPicture(id);
    }
}
